package com.demo.modules.mq.rabbit.service.direct;

import com.demo.common.core.utils.uuid.IdUtils;
import com.demo.modules.mq.rabbit.RabbitAnnouncementMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFutureCallback;

/**
 * 消息生产者
 *
 * @author Rog
 */
@Slf4j
@Component
public class RabbitDirectMessageProducerService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送到direct交换机
     */
    public void directQueue() {
        String exeChange = "wr.direct";
        log.info("发送消息到direct交换机");
        //发送的消息
        RabbitAnnouncementMessage rabbitAnnouncementMessage = new RabbitAnnouncementMessage();
        rabbitAnnouncementMessage.setId("1");
        rabbitAnnouncementMessage.setContent("helle,tow queue");
        //指定key，对应交换器的过滤字符
        String routKet = "info";
        rabbitTemplate.convertAndSend(exeChange, routKet, rabbitAnnouncementMessage);
    }
}

